#include<iostream>
#include<vector>

using namespace std;

class Solution {
public:
    int minSwaps(vector<int>& nums) {
        int n=nums.size();
        int cnt=reduce(nums.begin(),nums.end());
        if(cnt==0) return 0;
        int zero=0,ans=INT_MAX;
        for(int left=0,right=0;right<2*n;++right)
        {
            if(nums[right%n]==0) ++zero;
            while(left<right&&right-left+1>cnt)
            {
                if(nums[left%n]==0) --zero;
                ++left;
            }
            if(right-left+1==cnt) ans=min(ans,zero);
        }
        return ans;
    }
};